package 曾世昌12_9.zuoye4;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class demo {
    public static void main(String[] args) throws Exception {
        System.out.println("【查询手机】");
        System.out.println("1.黑色\t2.白色\t3.银色\t4.金色\t5.退出");
        int nextInt =   new Scanner( System.in ).nextInt();
        String str="";
        switch (nextInt){
            case 1:str="黑色";break;
            case 2:str="白色";break;
            case 3:str="银色";break;
            case 4:str="金色";break;
            case 5:return;
        }

        ArrayList<phone> phones = new ArrayList<>();
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read( "E:\\untitled5\\src\\mxdx3\\day6\\zuoye4\\phones.xml" );
        Element rootElement = read.getRootElement();
        List <Element>product = rootElement.elements( "product" );
        for (Element element : product) {
            if (element.elementText( "color" ).equals( str )){
                phones.add( new phone(element.elementText( "name" ),element.elementText( "brand" ),Double.parseDouble( element.elementText( "size" ) ),Integer.parseInt(  element.elementText( "price" ) ) ,element.elementText( "color" )) );
            }
        }
        System.out.println(phones);
    }
}
